package com.yzw.rabbitmq.consumer;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;


/**
 * @Athor:Yuan
 * @Date:2020/5/12 17:46
 * Desc:
 */
@Component
public class SimpleConsumer {
        // 通过注解自动创建 spring.simple.queue 队列
        @RabbitListener(queues = "mq")
        public void listen(String ms ,Message message , Channel channel) {
            System.out.println("简单队列 接收到消息：" + ms);
            try {
                channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }


}
